package com.ycx.ycxmybatismanagement.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class MyAspectAnnotation {

    @Pointcut("@annotation(com.ycx.ycxmybatismanagement.aop.MyLog)")
    public void pc(){}

    @Before("pc()")
    public void before(JoinPoint jp){
        Signature signature = jp.getSignature();
        String methodName = signature.getName();
        String className = signature.getDeclaringTypeName();
        log.info("before methodName:{} clasname:{}",methodName, className );

    }
    @Around("pc()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        Signature signature = pjp.getSignature();
        String methodName = signature.getName();
        String className = signature.getDeclaringTypeName();
        Object[] args = pjp.getArgs();
        Object result = pjp.proceed();
        log.info("around methodName:{} clasname:{} args:{} return:{}",methodName, className,args,result);
        return result;
    }





    @After("@annotation(ml)")
    public void After(MyLog ml) throws Throwable {
        log.info("After");
    }


}
